<template>
	<view class="global">
		<uni-nav-bar dark :fixed="true" shadow background-color="#007AFF" status-bar title="地址管理" @clickLeft="back"
			leftText="返回" title-align="left" />
		<view class="addressglobal">
			<view class="addressitem" @click="goitem(item.id)" v-for="item in addresslist">
				<view class="addressname">
					{{item.address}}
				</view>
				<view class="addresremark">
					{{item.user}} {{item.phone}}
				</view>
				<view class="edit">
					<image src="../../static/edit.png" @click.stop="editaddress(item)" style="width: 10px;height: 10px;" mode=""></image>
					<image src="../../static/qk.png" @click.stop="deleteaddress(item.id)" style="width: 10px;height: 10px;" mode=""></image>

				</view>
			</view>
		</view>
		<view class="tijiaodingdan">
			<button type="primary" @click="submitdingdan()">新增地址</button>
		</view>
	</view>
</template>

<script>
	import $H from '../../utils/request.js';
	export default {
		data() {
			return {
				addresslist: [],
				busid:"",
				comment:""
			}
		},
		onShow() {
			this.getaddress()
		},
		onLoad(e) {
			this.user = uni.getStorageSync("userinfo");
			console.log(e)
			if(e.businessId){
				this.busid=e.businessId
			}
			if(e.comment){
				this.comment=e.comment
			}
			
		},
		methods: {
			editaddress(id){
				uni.navigateTo({
					url:"/pages/addAdress/addAdress?item="+JSON.stringify(id)
				})
			},
			submitdingdan(){
				uni.navigateTo({
					url:"/pages/addAdress/addAdress"
				})
			},
			goitem(id){
				if(this.busid!== ""){
				uni.navigateTo({
					url:`/pages/orderItem/orderItem?busid=${this.busid}&addressid=${id}&comment=${this.comment}`
				})					
				}

			},
			getaddress() {
				$H.post("address/all?userId="+this.user.id).then(res => {
					console.log(res);
					this.addresslist = res.data

				})
			},
			deleteaddress(id){
			$H.post("address/delete?id="+id).then(res => {
					console.log(res);
					this.getaddress()

				})
				
			},
			back() {
				uni.navigateBack()
			}
		}
	}
</script>

<style scoped>
	.edit image {
		margin-right: 10px;
	}

	.tijiaodingdan {
		position: fixed;
		padding: 10px;
		box-sizing: border-box;
		bottom: 0px;
		width: 100%;
		left: 0px;
	}

	.edit {
		text-align: right;
	}

	.addressglobal {
		width: 100%;
		height: 80%;
		overflow: auto;

		padding: 10px;
		box-sizing: border-box;
	}

	.global {
		width: 100%;
		height: 100%;

		background: #e5e5e5;
	}

	.addressname {
		font-size: 14px;
		font-weight: bold;
		margin-bottom: 10px;
	}

	.addresremark {
		font-size: 14px;
		color: #e5e5e5;
		margin-bottom: 20px;
	}

	.addressitem {
		width: 100%;
		height: auto;
		padding: 10px;
		margin-bottom: 10px;
		box-sizing: border-box;
		background: #fff;
	}
</style>
